<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Grid布局基础</title>
    <style>
        /* 基础样式 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: Arial, sans-serif;
            line-height: 1.6;
            padding: 2rem;
        }

        h2 {
            margin: 2rem 0 1rem;
        }

        .grid-item {
            padding: 1rem;
            background-color: #4a90e2;
            color: white;
            border-radius: 4px;
            text-align: center;
        }

        /* 示例1：基本网格 */
        .basic-grid {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 1rem;
            margin-bottom: 2rem;
        }

        /* 示例2：不同列宽 */
        .varied-columns {
            display: grid;
            grid-template-columns: 2fr 1fr 1fr;
            gap: 1rem;
            margin-bottom: 2rem;
        }

        /* 示例3：指定行高 */
        .specific-rows {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            grid-template-rows: 100px 50px;
            gap: 1rem;
            margin-bottom: 2rem;
        }

        /* 示例4：网格线定位 */
        .grid-lines {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            grid-template-rows: repeat(2, 100px);
            gap: 1rem;
            margin-bottom: 2rem;
        }

        .grid-lines .span-2-cols {
            grid-column: 1 / 3;
            background-color: #357abd;
        }

        .grid-lines .span-2-rows {
            grid-row: 1 / 3;
            grid-column: 3;
            background-color: #357abd;
        }

        /* 示例5：自动填充 */
        .auto-fill {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
            gap: 1rem;
            margin-bottom: 2rem;
        }

        /* 工具类 */
        .debug-grid {
            position: relative;
        }

        .debug-grid::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: linear-gradient(to right, rgba(0,0,0,0.1) 1px, transparent 1px),
                        linear-gradient(to bottom, rgba(0,0,0,0.1) 1px, transparent 1px);
            background-size: 33.33% 50%;
            pointer-events: none;
        }
    </style>
</head>
<body>
    <h1>Grid布局基础示例</h1>

    <h2>1. 基本网格（3列等宽）</h2>
    <div class="basic-grid debug-grid">
        <div class="grid-item">1</div>
        <div class="grid-item">2</div>
        <div class="grid-item">3</div>
        <div class="grid-item">4</div>
        <div class="grid-item">5</div>
        <div class="grid-item">6</div>
    </div>

    <h2>2. 不同列宽（2:1:1）</h2>
    <div class="varied-columns debug-grid">
        <div class="grid-item">1</div>
        <div class="grid-item">2</div>
        <div class="grid-item">3</div>
        <div class="grid-item">4</div>
        <div class="grid-item">5</div>
        <div class="grid-item">6</div>
    </div>

    <h2>3. 指定行高</h2>
    <div class="specific-rows debug-grid">
        <div class="grid-item">1</div>
        <div class="grid-item">2</div>
        <div class="grid-item">3</div>
        <div class="grid-item">4</div>
        <div class="grid-item">5</div>
        <div class="grid-item">6</div>
    </div>

    <h2>4. 网格线定位</h2>
    <div class="grid-lines debug-grid">
        <div class="grid-item span-2-cols">跨越2列</div>
        <div class="grid-item span-2-rows">跨越2行</div>
        <div class="grid-item">3</div>
        <div class="grid-item">4</div>
    </div>

    <h2>5. 自动填充</h2>
    <div class="auto-fill">
        <div class="grid-item">1</div>
        <div class="grid-item">2</div>
        <div class="grid-item">3</div>
        <div class="grid-item">4</div>
        <div class="grid-item">5</div>
        <div class="grid-item">6</div>
        <div class="grid-item">7</div>
        <div class="grid-item">8</div>
    </div>

    <script>
        // 添加调试网格切换功能
        document.addEventListener('keydown', (e) => {
            if (e.key === 'g' && e.ctrlKey) {
                document.querySelectorAll('.debug-grid').forEach(grid => {
                    grid.classList.toggle('show-grid');
                });
            }
        });
    </script>
</body>
</html>
